package com.dhcc.core.api.auth.impl;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.Authenticator;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import com.dhcc.core.api.auth.IUserAuth;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.util.SpringContextHolder;
import com.dhcc.core.modules.system.entity.User;
import com.dhcc.core.modules.system.service.IUserService;
@Component("userAuth")
@ConditionalOnProperty(prefix = "sys", name = "authType", havingValue = "common")
public class CommonAuthImpl implements IUserAuth {

    @Override
    public R doAuth(String loginName, String password) {
        // TODO Auto-generated method stub
/*
        AuthenticationInfo authenticate = null;
        try {
            Authenticator authenticator = SpringContextHolder.getBean(Authenticator.class);
            UsernamePasswordToken token = new UsernamePasswordToken(loginName, password);
            authenticate = authenticator.authenticate(token);
        } catch (Exception e) {
            return R.error("用户名密码错误！");
        }
        if (authenticate == null) {
            return R.error("用户名密码错误！");
        }*/
    	
    	IUserService userService = SpringContextHolder.getBean(IUserService.class);
        User user = userService.authenticate(loginName, password);
        if (user == null) {
            return R.error("用户名密码错误！");
        }

        return R.ok();

    }

}
